mport java.io.*;
        import java.net.HttpURLConnection;
        import java.net.MalformedURLException;
        import java.net.URL;

/**
 * Created by lanouhn on 17/7/18.
 */
public class javanet {
    public static  void main(String [] a){
        //java的网络请求
        //处理网址url
        HttpURLConnection connection = null;

        InputStream is =null;//输入流，接收网络请求结果
        try{
            String myUrl = "http://c.3g.163.com/nc/article/list/T1348648517839/0-20.html";
            URL url = new URL(myUrl);

            connection =(HttpURLConnection) url.openConnection();

            int code = connection.getResponseCode();


            if(code == 200){
                is = connection.getInputStream();//读取输入流，将结果转换为Stirng
                //按行读
                BufferedReader br = new BufferedReader(new InputStreamReader(is));

                //定义接收结果的String
                String line = "";
                StringBuffer sb = new StringBuffer();
                //一行一行的读取赋值给line 如果不为空，继续循环，并拼接给sb
                while ((line = br.readLine()) != null){
                    sb.append(line);
                }
                String result  = sb.toString();
                System.out.println();

                String path =
                        File file = new File(path);

                FileWriter fw = new FileWriter(file);
                BufferedWriter writer = new BufferedWriter(fw);
                writer.write(result);
            }

        }catch (MalformedURLException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            //关流，断网
            if(connection!= null){
                connection.disconnect();
            }
            if(is != null){
                is.close();
            }

        }


    }
}